﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace iCPUApp.Code
{
    class BIOS
    {
        
              ManagementObject mo;
              Dictionary<int,string> BiosCharList = new Dictionary<int,string>();
              public BIOS()
              {
                  ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_BIOS");
                  foreach(ManagementObject m in mos.Get())
                  {
                      mo = m;
                      break;
                  }
                  /*Bioschar List */
                    BiosCharList.Add(0,"Reserved");
                    BiosCharList.Add(1,"Reserved");
                    BiosCharList.Add(2,"Unknown");
                    BiosCharList.Add(3,"BIOS Characteristics Not Supported");
                    BiosCharList.Add(4,"ISA is supported");
                    BiosCharList.Add(5,"MCA is supported");
                    BiosCharList.Add(6,"EISA is supported");
                    BiosCharList.Add(7,"PCI is supported");
                    BiosCharList.Add(8,"PC Card (PCMCIA) is supported");
                    BiosCharList.Add(9,"Plug and Play is supported");
                    BiosCharList.Add(10,"APM is supported");
                    BiosCharList.Add(11,"BIOS is Upgradable (Flash)");
                    BiosCharList.Add(12,"BIOS shadowing is allowed");
                    BiosCharList.Add(13,"VL-VESA is supported");
                    BiosCharList.Add(14,"ESCD support is available");
                    BiosCharList.Add(15,"Boot from CD is supported");
                    BiosCharList.Add(16,"Selectable Boot is supported");
                    BiosCharList.Add(17,"BIOS ROM is socketed");
                    BiosCharList.Add(18,"Boot From PC Card (PCMCIA) is supported");
                    BiosCharList.Add(19,"EDD (Enhanced Disk Drive) Specification is supported");
                    BiosCharList.Add(20,"Int 13h - Japanese Floppy for NEC 9800 1.2mb (3.5, 1k Bytes/Sector, 360 RPM) is supported");
                    BiosCharList.Add(21,"Int 13h - Japanese Floppy for Toshiba 1.2mb (3.5, 360 RPM) is supported");
                    BiosCharList.Add(22,"Int 13h - 5.25 / 360 KB Floppy Services are supported");
                    BiosCharList.Add(23,"Int 13h - 5.25 /1.2MB Floppy Services are supported");
                    BiosCharList.Add(24,"Int 13h - 3.5 / 720 KB Floppy Services are supported");
                    BiosCharList.Add(25,"Int 13h - 3.5 / 2.88 MB Floppy Services are supported");
                    BiosCharList.Add(26,"Int 5h, Print Screen Service is supported");
                    BiosCharList.Add(27,"Int 9h, 8042 Keyboard services are supported");
                    BiosCharList.Add(28,"Int 14h, Serial Services are supported");
                    BiosCharList.Add(29,"Int 17h, printer services are supported");
                    BiosCharList.Add(30,"Int 10h, CGA/Mono Video Services are supported");
                    BiosCharList.Add(31,"NEC PC-98");
                    BiosCharList.Add(32,"ACPI is supported");
                    BiosCharList.Add(33,"USB Legacy is supported");
                    BiosCharList.Add(34,"AGP is supported");
                    BiosCharList.Add(35,"I2O boot is supported");
                    BiosCharList.Add(36,"LS-120 boot is supported");
                    BiosCharList.Add(37,"ATAPI ZIP Drive boot is supported");
                    BiosCharList.Add(38,"1394 boot is supported");
                    BiosCharList.Add(39,"Smart Battery is supported");
              }
              
               private UInt16[] GetBiosCharDigits()
               {
                   UInt16[] bioschar =(UInt16[])mo["BiosCharacteristics"];
                   return bioschar;
               }
               
              public List<string> BiosCharacteristics
              {
                   get{
                       List<string> BiosChar= new List<string>();
                       foreach(UInt16 uin in GetBiosCharDigits())
                       {
                           try
                           {
                               BiosChar.Add(BiosCharList[uin]);
                           }
                           catch
                           {

                           }
                       }
                       return BiosChar;
                      }
              }

              public string GetStringProperty(string PropertyName)
              {
                  try
                  {
                      return mo.GetPropertyValue(PropertyName).ToString();
                  }
                  catch
                  {
                       return "N/A";
                  }
              }
              public string BuildNumber
              {
                 get{return GetStringProperty("BuildNumber");}
              }
              public string CurrentLanguage
              {
                 get{return GetStringProperty("CurrentLanguage");}
              }
              public string Description
              {
                 get{return GetStringProperty("Description");}
              }   
              public string IdentificationCode
              {
                 get{return GetStringProperty("IdentificationCode");}
              }
              public string LanguageEdition
              {
                 get{return GetStringProperty("LanguageEdition");}
              }
              public string Manufacturer
              {
                 get{return GetStringProperty("Manufacturer");}
              }
              public string SerialNumber
              {
                 get{return GetStringProperty("SerialNumber");}
              }
              public string SMBIOSBIOSVersion
              {
                 get{return GetStringProperty("SMBIOSBIOSVersion");}
              } 
              public string SMBIOSMajorVersion
              {
                 get{return GetStringProperty("SMBIOSMajorVersion");}
              }
              public string IsPrimaryBIOS
              {
                  get { return GetStringProperty("PrimaryBIOS"); }
              } 
              public string SMBIOSMinorVersion
              {
                 get{return GetStringProperty("SMBIOSMinorVersion");}
              } 
              public string IsSMBIOSPresent
              {
                 get{return GetStringProperty("SMBIOSPresent");}
              } 
              public string Version
              {
                 get{return GetStringProperty("Version");}
              } 
    }
}
